#include "StdAfx.h"
#include "NetMsgListener.h"
#include <fgeMessageManager.h>
#include "oclMsg.h"

using namespace fge;
using namespace protocol;

u_long	WINAPI SendToServer( const char* body, u_long size )
{
	return INSTANCE(ocl::TcpClient)->Send(body,size);
}
u_long	WINAPI SendToServer( u_long msgid, const void* body, u_long size)
{
	protocol::NetMsg head;
	head.msg_id = msgid;
	head.msg_len = size;
	head.msg_num = 1;
	ocl::Packer	msg;
	msg.AddToBuf(&head,sizeof(head));
	if(body)
		msg.AddToBuf(body,size);
	INSTANCE(ocl::TcpClient)->Send(msg(),msg.GetBufferLen());
	return msg.GetBufferLen();
}

CNetMsgListener::CNetMsgListener(void)
{
}

CNetMsgListener::~CNetMsgListener(void)
{
}

void	CNetMsgListener::OnDisconnect( )
{
}
void	CNetMsgListener::OnSend( const char* body, u_long size )
{

}
void	CNetMsgListener::OnRecv( const char* body, u_long size )
{
	if( size<=0 )
		return;

	CMessageManager* pMsgQueue = INSTANCE(CGameServer)->GetMessageQueue();
	NetMsg *pMsg = (NetMsg*)body;
	if(pMsg->msg_len <= size)
		pMsgQueue->Push(pMsg->msg_id,(BYTE*)pMsg,sizeof(NetMsg),(BYTE*)(pMsg+1),size-sizeof(NetMsg));
}
void	CNetMsgListener::OnClose( )
{

}
